import event from '../../net/event'

// initial state
// shape: [{ id, quantity }]
const state = {
  received_events_data_list: [],
  home_slider_list:[]
}

// getters
const getters = {}

// actions
const actions = {
  getPictures ({commit, state}, params) {
    event.getPictures(params.column,params.limit).then((res)=>{
        let data = res.data
        data.forEach((item) => {
          item.src = item.content_detail.assets_path
        })
      commit('storeSlider', data)
    })
  },
  getEventReceived ({commit, state}, params) {
    let page = params.page
    event.getEventReceived(page, params.type).then((res) => {
      if (res && res.data.data){
      let data = res.data.data
      data.forEach((item) => {
        let ex = {
          id: item.id,
          name: item.name,
          price: item.price,
          image: item.image,
          count: item.user_count,
        }
        item.ex = ex
    })
      if (page <= 1) {
        commit('storeEventReceived', data)
      } else {
        commit('addEventReceived', data)
      }
    }
    params.callback && params.callback(res)
  })

  },
}

// mutations
const mutations = {
  storeEventReceived (state, list) {
    state.received_events_data_list = list
  },
  addEventReceived (state, list) {
    state.received_events_data_list = state.received_events_data_list.concat(
      list)
  },
  storeSlider(state, list){
    state.home_slider_list = list
  }
}

export default {
  state,
  getters,
  actions,
  mutations,
}
